/*
 * @(#)AtcDAOImpl.java $version 2012-8-10
 * 
 * Copyright 2012 NADOSTAR Gruop. All rights Reserved.
 * NADOSTAR PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nadostar.iims.monitoring.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.nadostar.extensions.SimpleSqlMapDaoSupport;
import com.nadostar.extensions.util.DataMap;
import com.nadostar.iims.model.MonitoringParamModel;
import com.nadostar.iims.monitoring.dao.AtcDAO;

/**
 * The Class AtcDAOImpl.
 * 
 * @author Lixing
 *
 */
@Repository("AtcDAO")
public class AtcDAOImpl extends SimpleSqlMapDaoSupport implements AtcDAO {
	private static final String PREFIX = "com.nadostar.iims.bbs.atc.";
	
	@SuppressWarnings("unchecked")
	public List<DataMap> selectMonitoringList(MonitoringParamModel model, int offset, int count) throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bbsTypeCd", model.getBbsTypeCd());
		params.put("trtStat", model.getTrtStat());
		params.put("startDate", model.getStartDate());
		params.put("endDate", model.getEndDate());
		params.put("wrtrMbrId", model.getWrtrMbrId());
		params.put("offset", offset);
		params.put("count", count);
		
		return getSqlMapClientTemplate().queryForList(PREFIX + "selectMonitoringList", params);
	}

	public int selectMonitoringListCount(MonitoringParamModel model) throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bbsTypeCd", model.getBbsTypeCd());
		params.put("trtStat", model.getTrtStat());
		params.put("startDate", model.getStartDate());
		params.put("endDate", model.getEndDate());
		params.put("wrtrMbrId", model.getWrtrMbrId());
		
		return (Integer) getSqlMapClientTemplate().queryForObject(PREFIX + "selectMonitoringListCount", params);
	}

	public int updateTrtrStat() throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		
		return getSqlMapClientTemplate().update(PREFIX + "updateTrtrStat", params);
	}

	@SuppressWarnings("unchecked")
	public List<DataMap> selectDeletedMonitoringList(MonitoringParamModel model, int offset, int count) throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bbsTypeCd", model.getBbsTypeCd());
		params.put("productNo", model.getProductNo());
		params.put("startDate", model.getStartDate());
		params.put("endDate", model.getEndDate());
		params.put("wrtrMbrId", model.getWrtrMbrId());
		params.put("offset", offset);
		params.put("count", count);
		
		return getSqlMapClientTemplate().queryForList(PREFIX + "selectDeletedMonitoringList", params);
	}

	public int selectDeletedMonitoringListCount(MonitoringParamModel model) throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("bbsTypeCd", model.getBbsTypeCd());
		params.put("productNo", model.getProductNo());
		params.put("startDate", model.getStartDate());
		params.put("endDate", model.getEndDate());
		params.put("wrtrMbrId", model.getWrtrMbrId());
		
		return (Integer) getSqlMapClientTemplate().queryForObject(PREFIX + "selectDeletedMonitoringListCount", params);
	}

	@SuppressWarnings("unchecked")
	public List<DataMap> selectMonitoringStatistics(MonitoringParamModel model) throws DataAccessException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startDate", model.getStartDate());
		params.put("endDate", model.getEndDate());
		params.put("bbsTypeCd", model.getBbsTypeCd());
		params.put("productNo", model.getProductNo());
		
		return getSqlMapClientTemplate().queryForList(PREFIX + "selectMonitoringStatistics", params);
	}

}
